package com.windrift.ws.order.client;

import com.windrift.ws.order.Order;
import com.windrift.ws.order.OrderProcess;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

/**
 * Created by IntelliJ IDEA.
 * User: cy
 * Date: 10/05/12
 * Time: 11:08 AM
 * To change this template use File | Settings | File Templates.
 */
public class Client {
    private static String CLIENT_CONTEXT_DEF_FILE = "src/main/resources/client-beans.xml";
    
    public static void main(String args[]) throws Exception {
        // START SNIPPET: client
        ApplicationContext context = new FileSystemXmlApplicationContext(new String[]
                {CLIENT_CONTEXT_DEF_FILE});
        OrderProcess client = (OrderProcess) context.
                getBean("orderClient");
        // Populate the Order bean
        Order order = new Order();
        order.setCustomerId("C001");
        order.setItemId("I001");
        order.setQty(100);
        order.setPrice(200.00);
        String orderId = client.processOrder(order);
        String message = (orderId == null) ?
                "Order not approved" : "Order approved order ID is " + orderId;
        System.out.println(message);
        System.exit(0);
    }
}
